package zero;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.Socket;

/**
 * 基于IO的数据传输 零拷贝数据传输
 * @author yunlongn
 */
public class OldClient {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("localhost", 8899);


        String filePath = "D:\\book\\A从 0 开始带你成为MySQL实战优化高手.pdf";
        InputStream inputStream = new FileInputStream(filePath);

        DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());

        byte[] buffer = new byte[4096];
        long readCount;
        long total = 0;
        long startTime = System.currentTimeMillis();

        while ((readCount = inputStream.read(buffer)) >= 0) {

            total += readCount;
            outputStream.write(buffer);
        }

        socket.close();
        // 发送总字节数 88911673 耗时：391
        System.out.println("发送总字节数 " + total + " 耗时：" +  (System.currentTimeMillis() - startTime));
        inputStream.close();
        outputStream.close();
        Thread.sleep(1000000000);
    }
}
